#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        bool flag = false;
        for (int j = nums.size() - 1; j >= 0; j--) {
            for (int i = j; i >= 0; i--) {
                if (nums[i] < nums[j]) {
                    int tmp = nums[j];
                    for (int k = j; k > i; k--) {
                        nums[k] = nums[k - 1];
                    }
                    nums[i] = tmp;
                    return;
                }
            }
        }
        sort(nums.begin(), nums.end());
    }
};